package com.imooc.service.impl;

import com.imooc.mapper.StuMapper;
import com.imooc.pojo.Stu;
import com.imooc.service.StuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @ClassName: StuServiceImpl
 * @Package: com.imooc.service.impl
 * @Description:
 * @Date: 2021/7/5 11:26
 * @Author: sunzheng@beiming.com
 */
@Service
public class StuServiceImpl implements StuService {

  @Autowired
  private StuMapper stuMapper;

  @Transactional(propagation = Propagation.SUPPORTS)
  @Override
  public Stu getStuInfo(Integer id) {
    return stuMapper.selectByPrimaryKey(id);
  }

  @Transactional(propagation = Propagation.REQUIRED)
  @Override
  public void saveStu() {

    Stu stu = new Stu();
    stu.setName("孙政");
    stu.setAge(22);
    stuMapper.insert(stu);

  }

  @Transactional(propagation = Propagation.REQUIRED)
  @Override
  public void updateStu(Integer id) {

    Stu stu = new Stu();
    stu.setId(id);
    stu.setName("孙悟空");
    stu.setAge(99999);
    stuMapper.updateByPrimaryKey(stu);

  }

  @Transactional(propagation = Propagation.REQUIRED)
  @Override
  public void deleteStu(Integer id) {

    stuMapper.deleteByPrimaryKey(id);

  }
}
